package org.luxor.common.netty.protocol.handler.keepalive;

import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import org.luxor.common.netty.protocol.message.NettyPongMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 心跳应答
 *
 * @author Mr.yan @date 2023/12/4
 */
@ChannelHandler.Sharable
public class PongMessageHandler extends SimpleChannelInboundHandler<NettyPongMessage> {
    private static final Logger log = LoggerFactory.getLogger(PongMessageHandler.class);

    private String sid;

    public PongMessageHandler(String sid) {
        this.sid = sid;
    }

    @Override
    public void channelRead0(ChannelHandlerContext ctx, NettyPongMessage msg) throws Exception {
    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
        log.warn("[id:{}({})] The client received Event:'exceptionCaught' channel close.", ctx.channel().id(), this.sid, cause);
        ctx.close();
    }

}
